package cn.hinglo.gameclaw.client.service;

import cn.hinglo.gameclaw.client.dao.BannerClientDao;
import cn.hinglo.gameclaw.data.utils.CommonUtils;
import cn.hinglo.gameclaw.data.utils.FieldUtils;
import cn.hinglo.gameclaw.user.bean.Banner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @createTime: 2018/1/8
 * @author: HingLo
 * @description: banner service
 */
@Service
@CacheConfig(cacheNames = "banner")
public class BannerClientService {

    private final BannerClientDao bannerClientDao;

    @Autowired
    public BannerClientService(BannerClientDao bannerClientDao) {
        this.bannerClientDao = bannerClientDao;
    }

    /**
     * 查询全部的banner集合
     *
     * @return banner图列表
     */
    @Cacheable
    public List<Banner> listBannerClientService() {
        Banner banner = new Banner().setStatus(true);
        List<Banner> list = bannerClientDao.select(banner);
        list.forEach(x -> x.setImageUrl(CommonUtils.imgInstall(x.getImageUrl(), FieldUtils.IMAGE_1)));
        return list;
    }

}
